package xyz.jangle.design.composite;

import java.util.Iterator;
import java.util.LinkedList;
/**
 * Composite节点
 * @author Administrator
 *
 */
public class Composite implements Component {
	
	private LinkedList<Component> child;

	public Composite() {
		super();
		child = new LinkedList<Component>();
	}

	@Override
	public void add(Component component) {
		child.add(component);
	}

	@Override
	public void remove(Component component) {
		child.remove(component);
	}

	@Override
	public Component getChild(int i) {
		return child.get(i);
	}

	@Override
	public void opration() {
		System.out.println(this+"  Composite to do something");
		Iterator<Component> iterator = child.iterator();
		while(iterator.hasNext()) {
			Component component = iterator.next();
			component.opration();
		}

	}

}
